<%@ page contentType="text/html; charset=UTF-8"%>
<%@ include file="/WEB-INF/jsp/sys/include.jsp"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<base href="<%=basePath%>"/>
<title>用户管理</title>
<link href="css/global.css" type="text/css" rel="stylesheet"/>

	<link rel="stylesheet" type="text/css" href="css/easydialog.css" />
	<script src="js/easydialog.min.js" type="text/javascript"></script>
	<script src="js/jquery-1.5.1.js" type="text/javascript"></script>
	<script src="js/jquery.form.js" type="text/javascript"></script>
	<script src="js/jquery.validate.js" type="text/javascript"></script>
	<script src="js/jquery.validate.ms.js" type="text/javascript"></script>
	

<style type="text/css">
<!--
body{
	background-color:#ffffff;
	margin:0px; padding:0px;
}
label.error{
	font-weight: bold;
	color: red;
}
-->
</style>
</head>

	<body>
	<div id="main">

	<div id="part1" class="part">
		<p class="title"><a href="#">添加用户</a></p>
		<div class="doc" id="doc2">
				<form id="addDataId">
				<ta:formToken/>
			<table>
			<tr><td>登录ID:</td><td><input id="loginID_id" name="loginID" type="text" class="txt" /></td></tr>
			<tr><td>密码:</td><td><input id="password_id" name="password" type="password" class="txt" /></td></tr>
			<tr><td>重复密码:</td><td><input id="confirm_password_id" name="confirm_password" type="password" class="txt"/></td></tr>
			<tr><td>姓名:</td><td><input id="name_id" name="name" type="text" class="txt"/></td></tr>
			<tr><td>性别:</td><td><input id="gender_id" name="gender" type="text" class="txt" /></td></tr>
			<tr><td>电邮:</td><td><input id="email_id" name="email" type="text" class="txt" /></td></tr>
			<tr><td>电话:</td><td><input id="phone_id" name="phone" type="text" class="txt"/></td></tr>
			<tr><td>移动电话:</td><td><input id="mobile_id" name="mobile" type="text" class="txt"/></td></tr>
			<tr><td>单位:</td><td><input id="orgID_id" name="orgID" type="text" class="txt" /></td></tr>
			<tr><td>是否管理员:</td><td><input id="isAdmin_id" name="isAdmin" type="text" class="txt" /></td>
			</tr>
			<tr>
			<td><input value="提交" type="button" id="submitId" class="btn"/> 
				<input value="重置" type="button" id="resetId" class="btn"/></td><td></td>
			</tr>
			</table>	
				
				</form>
		</div>
	</div>
	
	</div>
	<%--
	<input type="button" value="fff" onclick="javascript:alert(document.getElementById('addDataId').innerHTML)"/>
	 --%>
	</body>
<script type="text/javascript">
$(document).ready(function(){
	var validator = $("#addDataId").validate({
		debug:true,
		focusInvalid: true,//表单提交时,焦点会指向第一个没有通过验证的域
		success: function(label) {
			 label.html("<font color='green'>正确！</font>");
			
		},
		errorPlacement: function(error, element) {
                    error.appendTo(element.parent());
                },   
		rules: {
			loginID:{
				required:true,
				remote:{
			        type:"POST",
			        url:"sysQueryUserByUsername.do", 
			        data:{
			        	loginID: function() {
				            return $("#loginID_id").val();
				        }
			        }
				}
			},
			name:{
				required:true,
				rangelength:[2,5]
			},
			password:{
				required:true,
				rangelength:[5,10]
			},
			confirm_password:{
				required: true,
				equalTo: "#password_id"
				
			},
			email:{
				email:true
			}
		},
		messages:{
			loginID:{
				required:"请输入用户名",
				remote:"用户名已经存在"
			},
			name:{
				required:"请输入密码",
				rangelength:"长度范围在2-5之间"
			},
			password: {
		    	required: "请输入密码",
				rangelength:"长度范围在5-10之间"
		   	},
		   	confirm_password:{
				required: "请输入确认密码",
    			equalTo: "两次输入密码不一致"
				
		   	}
			
		}
	});
	
	$('#submitId').click(function(){
			if(true == validator.form()){
				var options = {
					url:'sysUserAddAction.do',
					type:'POST',
					success:function(data) {
		         		if("true" == data){
		         			
		         			easyDialog.open({
								container : {
									header : '信息提示',
									content : '数据提交成功！',
									yesFn : function(){
		         							//return true;
		         							window.location="sysUserQuery.do";
		         							window.reload();
		         							}
								}
							});
									         			
		         		}else if("repeatSubmit" == data){
		         			easyDialog.open({
								container : {
									header : '信息提示',
									content : '数据已提交，请不要重复操作！',
									yesFn : function(){return true;}
								}
							});
		         		}else{
		         			
		         			easyDialog.open({
								container : {
									header : '信息提示',
									content : '数据提交失败！',
									yesFn : function(){return true;}
								}
							});
		         		}
		     		}
				};
				$('#addDataId').ajaxSubmit(options);
				return false;
			}else{
				return false;
			}
	    });

	$("#resetId").click(function() {
        validator.resetForm();
    });
});
</script>
</html>

